package com.mali.permission.controller;

import com.mali.common.dto.Result;
import com.mali.common.web.domain.dto.PageRequestDTO;
import com.mali.permission.service.PermissionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@Slf4j
@RestController
@RequestMapping("/permission")
@RequiredArgsConstructor
public class permissionController {

    // 注入PermissionService
    private final PermissionService permissionService;

    @GetMapping("/defaultRole")
    public Result<String> defaultRole(@RequestParam Long userId) {
        // 权限控制, 返回默认角色
        log.debug("请求======>绑定默认角色");
        return permissionService.bindDefaultRole(userId);
    }

    @GetMapping("/getCode")
    public Result<Integer> getRoleCode(@RequestParam Long userId) {
        // 获取角色权限码
        log.debug("请求======>获取角色权限码");
        return permissionService.getRoleCode(userId);
    }

    @PutMapping("/update/admin")
    public Result<Boolean> updateToAdmin(@RequestParam Long userId) {
        // 更新角色权限
        log.debug("请求======>更新角色到管理员");
        return permissionService.updateToAdmin(userId);
    }

    @PutMapping("/update/user")
    public Result<Boolean> updateToUser(@RequestParam Long userId) {
        // 获取角色码
        log.debug("请求======>更新角色到普通用户");
        return permissionService.updateToUser(userId);
    }

    @PostMapping("/commonUserList")
    public Result<Collection<Long>> getCommonUserList(@RequestBody PageRequestDTO pageRequestDTO) {
        log.debug("请求======>获取普通用户列表");
        return permissionService.getCommonUserList(pageRequestDTO);
    }

    @PostMapping("/adminUserList")
    public Result<Collection<Long>> getAdminUserList(@RequestBody PageRequestDTO pageRequestDTO) {
        log.debug("请求======>获取管理员列表");
        return permissionService.getAdminUserList(pageRequestDTO);
    }
}
